
<template>
  <div>
    <SearchForm
        @search="onSearch"
        @reset="onReset"
        :search-list="searchList" :search-params="searchParams">
    </SearchForm>

    <div class="table-layout">
      <el-card shadow="never">
        <div class="table-box">
          <el-table
              size="large"
              stripe
              border
              v-loading="loading"
              max-height="500px"
              :data="tableData"
              row-key="id"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(255, 255, 255, 0.8)"
              @selection-change="onSelect"
          >
            <el-table-column label="租户编号" align="center" prop="id" />
            <el-table-column label="租户名" align="center" prop="name" />
            <el-table-column label="租户套餐" align="center" prop="packageId">
              <template #default="scope">
                <el-tag v-if="scope.row.packageId === 0" type="danger">系统租户</el-tag>
                <template v-else v-for="item in packageList">
                  <el-tag type="success" :key="item.id" v-if="item.id === scope.row.packageId">
                    {{ item.name }}
                  </el-tag>
                </template>
              </template>
            </el-table-column>
            <el-table-column label="联系人" align="center" prop="contactName" />
            <el-table-column label="联系手机" align="center" prop="contactMobile" />
            <el-table-column label="账号额度" align="center" prop="accountCount">
              <template #default="scope">
                <el-tag>{{ scope.row.accountCount }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column
                label="过期时间"
                align="center"
                prop="expireTime"
                width="180"
                :formatter="dateFormatter"
            />
            <el-table-column label="绑定域名" align="center" prop="website" width="180" />
            <el-table-column label="租户状态" align="center" prop="status">
              <template #default="scope">
                <el-tag type="info" v-if="scope.row.status === 1">禁用</el-tag>
                <el-tag type="success" v-if="scope.row.status === 0">启用</el-tag>
              </template>
            </el-table-column>
            <el-table-column
                label="创建时间"
                align="center"
                prop="createTime"
                width="180"
                :formatter="dateFormatter"
            />
            <el-table-column label="操作" align="center" min-width="110" fixed="right">
              <template #default="scope">
                <el-button type="text" @click="onEdit(scope.row)">编辑</el-button>
                <el-button type="text" style="color: #F82222" @click="onDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-card>

      <div class="page-box">
        <el-pagination
            background
            :current-page="pageNo"
            :page-sizes="pageSizes"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalSize"
            @size-change="changePageSize"
            @current-change="changePageNo"
        />
      </div>
    </div>
    <Add ref="addFormRef" @get-page="initData" />
  </div>
</template>
<script>

import crud from "@/mixins/crud";
import { http } from "@/api";
import Add from "./add";
export default {
  name: "index",
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request:http.system.tenant,
      searchList: [
        {
          label: '租户名称',
          prop: 'name',
          name: 'input',
          clearable: true
        },
        {
          label: '联系人',
          prop: 'contactName',
          name: 'input',
          clearable: true
        },
        {
          label: '联系手机',
          prop: 'contactMobile',
          name: 'input',
          clearable: true
        },
        // 租户状态 0 开启 1关闭 status
        {
          label: '状态',
          prop: 'status',
          name: 'select',
          options: [
            { label: '启用', value: 0 },
            { label: '禁用', value: 1 }
          ],
          clearable: true
        },
          // 创建时间
        {
          label: '创建时间',
          prop: 'createTime',
          name: 'date',
          type: 'daterange',
          clearable: true
        }
      ],
      searchParams: {
        name: '',
        contactName: '',
        contactMobile: '',
        status: '',
        createTime: []
      },
      tableData: [

      ],
      packageList: []
    }
  },
  created() {
    http.system.tenantPackage.simpleList().then(res => {
      this.packageList = res.data
    })
  },
  methods: {
  }
}
</script>

<style scoped lang="scss">

</style>
